$(function() {
    var bdbLogin = {
        login: function() {
            var msgEle = $('#bdb-login-error-msg'),
            loginBtnEle = $('#bdb-login-btn');

            loginBtnEle.off('click').on('click', function() {
                msgEle.hide();
                var usr = $('#bdb-login-username').val(),
                    pwd = $('#bdb-login-pwd').val(),
                    msg = '帐号、密码不能为空';

                if (usr == '' || pwd == '') {
                    msgEle.text(msg).show();
                    return ;
                }

                $.ajax({
                    url: '/AdminUser/verifyLogin',
                    method: 'post',
                    dataType: 'json',
                    data: {email: usr, password: pwd},
                    success: function(reponse){
                        if (reponse.code == 0) {
                            window.location.href = '/';
                        } else if (reponse.code != 0) {
                            msg = reponse.msg;
                            msgEle.text(msg).show();
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {

                    }
                });
            });

            $('#bdb-login-username, #bdb-login-pwd')
                .off('keydown').on('keydown', function(e) {
                    if (e.keyCode == 13) {
                        loginBtnEle.click();
                    }
                });
        },
        animation: function() {
            $('#bdb-login-sinobbd').fadeOut(1, function() {
                $("#bdb-login-bg").addClass("bdb-login-bg-blur");
                $('#bdb-login-content').fadeIn(1);
            }); 
        },
        init: function() {
            this.login();
            this.animation();
            // this.showLogin();
        }
    };

    /* 初始化 */
    bdbLogin.init();
});
